package es.deusto.tralala.rmi.client;

import java.rmi.RMISecurityManager;
import java.util.UUID;

import es.deusto.tralala.data.dto.CancionDTO;
import es.deusto.tralala.data.dto.ReproduccionDTO;
import es.deusto.tralala.rmi.server.ITralalaFacade;

public class Client {
	static String uid = UUID.randomUUID().toString();
	
	public static void main(String[] args) {
		if (args.length != 3) {
			System.out.println("uso: java [policy] [codebase] cliente.Cliente [host] [port] [server]");
			System.exit(0);
		}

		if (System.getSecurityManager() == null) {
			System.setSecurityManager(new RMISecurityManager());
		}

		try {
			String name = "//" + args[0] + ":" + args[1] + "/" + args[2];
			ITralalaFacade server = (ITralalaFacade) java.rmi.Naming.lookup(name);
			System.out.println("* Message coming from the server: '" + server.sayHello() + "'");
			System.out.println(server.login(uid, "user", "user"));
			server.addReproduccion(uid, new ReproduccionDTO(server.getCancion("TNT")));
		} catch (Exception e) {
			System.err.println("- Exception running the client: " + e.getMessage());
			e.printStackTrace();
		}
	}
}